package com.yms.socket;

import java.io.IOException;
import java.nio.channels.Selector;

/**
 * @version : 1.0
 * @author: yangmingsong
 * @date: 2022/7/24-07-24-18:42
 * @description: spring5Test
 */
public class SelectorUtil {

    private static volatile Selector selector;

    private SelectorUtil(){}

    public static Selector getSelector(){
        if(selector == null){
            setSelector();
        }
        return selector;
    }

    private static void setSelector(){
        if(selector == null){
            synchronized (Selector.class){
                if(selector == null){
                    try {
                        selector = Selector.open();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }

    }
}
